package cn.wolfcode.tieba.service.impl;

import cn.wolfcode.tieba.domain.User;
import cn.wolfcode.tieba.exception.LogicException;
import cn.wolfcode.tieba.mapper.UserMapper;
import cn.wolfcode.tieba.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 王金龙
 * @date 2021/1/10 13:29
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public void regist(User user) {
        super.save(user);
    }

    @Override
    public User login(String name, String password)  {
        User user = super.getOne(new QueryWrapper<User>()
                .eq("name", name)
                .eq("password", password));
        if (user==null){
            throw new LogicException("账号或者密码错误");
        }
        return user;
    }

    @Override
    public User getByName(String name) {
        return super.getOne(new QueryWrapper<User>().eq("name", name));
    }

}
